<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 奖品设置
 */
class AwardSet extends Model
{
	use SoftDeletes;

	protected $fillable = ['activity_id', 'level_id', 'total', 'surplus', 'rate'];

    /**
     * 根据活动 activity_id 获取活动的所有奖品分类信息
     *
     * @param int|string $activity_id   活动 activity_id
     * @return array
     */
    public static function getAwardSetsByActivityId($activity_id = 0)
    {
        return self::select(['award_sets.id as award_set_id', 'award_sets.title', 'award_levels.title as level_title', 'award_sets.total'])
            ->join('activities', function($join){
                $join->on('activities.id', '=', 'award_sets.activity_id');
            })
            ->join('award_levels', function($join){
                $join->on('award_levels.id', '=', 'award_sets.level_id');
            })
            ->where(['activity_id' => $activity_id])
            ->get()->toArray();
    }
}